package edu.bupt.threadpool;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.BlockingQueue;

import edu.bupt.segmenter.ChSplitWord;

import segmenter.ChineseSegment;

public class SegmentHandler implements Runnable{

	/**
	 * @param args
	 */
	private BlockingQueue<String> wQueue;
	private BlockingQueue<String> fQueue;
	private static ChSplitWord cSegment = ChSplitWord.getInstance();
	
	public SegmentHandler(BlockingQueue<String> wQueue,BlockingQueue<String> fQueue){
		this.wQueue = wQueue;
		this.fQueue = fQueue;
	}

	@Override
	public void run() {
			List<String> list = new ArrayList<String>();
			if(wQueue.isEmpty())
				return;
			for(int i = 0;i < 50; i++){
				if(wQueue.isEmpty())
					break;
				try {
					list.add(wQueue.take());
				} catch (InterruptedException e) {
						e.printStackTrace();
				}
			}
			for(String str : list){
				try {
					System.out.println("准备分词：" + str);
					fQueue.put(cSegment.splitWord((str)));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		
	}

}
